package com.samxcode.leetcode;

/**
 * Determine whether an integer is a palindrome. Do this without extra space.
 * 
 * reverse the origin integer x that the index is from 1 to half into another integer, then check
 * 
 * @author Sam
 *
 */
public class PlindromicNumber {

    public static void main(String[] args) {
        System.out.println(isPalindrome(101));
    }


    public static boolean isPalindrome(int x) {
        if (x < 0 || (x != 0 && x % 10 == 0)) {
            return false;
        }
        int reverse = 0;
        while (x > reverse) {
            reverse = reverse * 10 + x % 10;
            x = x / 10;
        }
        return x == reverse || x == reverse / 10;
    }
}
